{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table align=\"left\">\n",
    "  <td>\n",
    "    <a href=\"https://colab.research.google.com/github/nyandwi/machine_learning_complete/blob/main/6_classical_machine_learning_with_scikit-learn/0_intro_to_sklearn.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
    "  </td>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*This notebook was created by [Jean de Dieu Nyandwi](https://twitter.com/jeande_d) for the love of machine learning community. For any feedback, errors or suggestion, he can be reached on email (johnjw7084 at gmail dot com), [Twitter](https://twitter.com/jeande_d), or [LinkedIn](https://linkedin.com/in/nyandwi).*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "B6Nc4flHV7oi"
   },
   "source": [
    "# Intro to Scikit-Learn for Shallow Machine Learning"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "zBoAz0oTYBpA"
   },
   "source": [
    "Scikit-Learn (aka sklearn) is a simple, beautifull and well designed machine learning library. \n",
    "\n",
    "Scikit-Learn provides various learning algorithms. Using them is as simple as filling a cup of coffee. \n",
    "\n",
    "Beyond learning algorithms, the library also provides data processing functions which are also very simple to use. In addition to those processing functions, Scikit-Learn offers other functions such as pipelines, model tuning, and much more. \n",
    "\n",
    "To learn more about Scikit-Learn, check out its [website](https://scikit-learn.org/stable/). It's to navigate and you will immediately see how well designed it is. \n",
    "\n",
    "To practice how simple Scikit-Learn is, let's build a simple linear regressor. Our goal is to fit a line. \n",
    "\n",
    "\n",
    "We will start with imports, in this case, we will import `Linear Regressor` from sklearn linear models. We will also imports `NumPy` which we will use to create our sample data and `Matplotlib` to plot the created data. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "HRmi944jiaj2"
   },
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "dNigh6U7jA9_"
   },
   "source": [
    "After we have imported Linear Regressor, we will create our data. It's a numpy array, `X` and `y`. If you are too quick to crunch the numbers, you are going to see that the X and y represent a linear equation `y=2X+1`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "BKM06806r7ZH"
   },
   "outputs": [],
   "source": [
    "X = np.array([[1.0],[2.0],[3.0],[4.0],[5.0],[6.0],[7.0],[8.0]], dtype='float')\n",
    "y = np.array([[3.0],[5.0],[7.0],[9.0],[11.0],[13.0],[15.0],[17.0]], dtype='float')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "voopj76OvTUN"
   },
   "source": [
    "Like we said, here is the relationship between X and y. It is a line. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 302
    },
    "id": "uUgYMauCunso",
    "outputId": "3233b152-695c-4218-d8a7-eff25d69ca32"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f98e7294490>]"
      ]
     },
     "execution_count": 59,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deVxVdf7H8dfXXVBxARUXBFdUcEVN2yxtMS0za6ppX8ap2Zotxay03ZZpmWkbK1umbQrQNFvMsrQ9rbwsgvuCCyAqIDvc7+8PmH6N44Jw4dxzeT8fDx/Bubd73g+Vt1++nPO5xlqLiIi4TxOnA4iISO2owEVEXEoF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xOk8p0MdQziw0hjjAb6jag/c7y/Pc4kuwOfGmHXAt8Aya+0HDmc6lt8Dr1X/XRgG3O9wnmOq/kfxLKpWtH6r+ruaBOB7IJmqzvXZLfV+fxmhiIgcmd+vwEVE5MhU4CIiLqUCFxFxKRW4iIhLqcBFRFxKBS4i4lIqcBERl/o/kulwx0FSkG0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light",
      "tags": []
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(X,y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "UqKrZCV7kPx5"
   },
   "source": [
    "Now that we have created the data, it's time to create a model. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "igpts5oekWDA"
   },
   "outputs": [],
   "source": [
    "model =  LinearRegression()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "L50WDBRbkcEj"
   },
   "source": [
    "That was simple. Next, we are going to train the model. Using `fit`method, we are going to pass the input data `X` and output data `y`. `y` is also referred to as a label. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "cZYeOvTnkxrl",
    "outputId": "5abd2f82-8d47-4129-ff99-4fde1bc8a83a"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)"
      ]
     },
     "execution_count": 45,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(X, y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "6aSfp82NmWnk"
   },
   "source": [
    "Huum, that was quick. Now the model is trained on the dataset. Let's try to see how confident it is on the data it never saw. We will create a test array having the numbers from 9 to 11, just to test if the predictions will be 19, 21, 23 respectively. Let's do that!!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "GKkFSSQMmkpI",
    "outputId": "e14a86a9-9112-4e9c-8f24-8311172973c3"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[19.],\n",
       "       [21.],\n",
       "       [23.]])"
      ]
     },
     "execution_count": 50,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_array = np.array([[9.0],[10.0],[11.0]], dtype='float')\n",
    "\n",
    "model.predict(test_array)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "R-nB8fFIszpb"
   },
   "source": [
    "As you can see, it did well. It was able to learn the relationship between X and y just from the data. This the what it means when we say that different to traditional programming which requires rules and data to give results, machine learning takes data and results and give the rules. \n",
    "\n",
    "Let's try to see the rules in our example. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "yEbgwNLctRp7",
    "outputId": "00eebbcd-8dd9-47cd-e2ea-3a1dc1c1d53b"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.]])"
      ]
     },
     "execution_count": 51,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "7dgqEyk4tTj5",
    "outputId": "20ecd7b0-0c0c-4ef0-ef8c-03172662faae"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.])"
      ]
     },
     "execution_count": 52,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.intercept_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "UvtHgUB1tb8w"
   },
   "source": [
    "Great, the model was able to determine the exact linear equation that we used when creating the data. The `coef` is the `coefficient`, commonly known to `weight`. So in this case it is 2, and it what is multplied to the input data `X`. On the other hand, 1 is the `intercept`, commonly known to `bias`. Combining them we get our equation, `y=2X+1`. These two parameters (weights and biases) are the two output components of any machine learning model. \n",
    "\n",
    "In our case, since the data was so simple, it is easy to directly tell that the output is a linear equation, but when it comes to the real world scenarios, it may be hard because you have many features and data points. \n",
    "\n",
    "\n",
    "Hopefully this was a good introduction to Machine Learning with Scikit-Learn. We have not touched to the whole of what we can do with Scikit-Learn and in the next labs, you will see more models applied to the real world datasets! \n"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "6.1 Intro to Scikit-Learn for Shallow Machine Learning.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
